<?php
class mis_data_perangkat_model1 extends MY_Model {
	var $nama_tabel = 'ADMIN_PRIMKOKAS.MIS_BARANG';
	function getJob()
	{
		$ls_sql	= "	SELECT	KODE_KONDISI value,
							KETERANGAN display
					FROM	ADMIN_PRIMKOKAS.MIS_KONDISI
					ORDER BY KODE_KONDISI";
					
		$result	= $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
	}
	function GetJSON() {
		$ls_sql	= "	SELECT	a.KODE_BARANG,a.NAMA_BARANG,a.TIPE,a.HARGA,a.JUMLAH,a.KETERANGAN,a.nama_unit
					FROM	".$this->nama_tabel." a 
					WHERE	UPPER(a.KODE_BARANG) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.NAMA_BARANG) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.NAMA_MEREK) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.SPESIFIKASI) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.TIPE) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.HARGA) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.JUMLAH) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.KETERANGAN) LIKE '%".strtoupper(post('keyword'))."%'
					ORDER BY ".(post('sort')=='' ? 'KODE_BARANG' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
	
		return json_encode( $this->paging($ls_sql) );

	}

	function Add($arr_data){
		$this->db->insert($this->nama_tabel, $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$this->db->update($this->nama_tabel, $arr_data, $arr_rule);
	}

	function GetSingle($as_no){
		$result = $this->db->query("SELECT	a.KODE_BARANG,a.NAMA_BARANG,a.TIPE,a.HARGA,a.JUMLAH,a.KETERANGAN,a.nama_unit
									FROM	".$this->nama_tabel." a 
									WHERE 	a.KODE_BARANG = '".$as_no."'");
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_no)
	{
		$result = $this->db->query("SELECT	a.KODE_BARANG,a.NAMA_BARANG,a.TIPE,a.HARGA,a.JUMLAH,a.KETERANGAN,a.nama_unit
										FROM	".$this->nama_tabel." a 
										WHERE 	a.KODE_BARANG = '".$as_no."'");
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule) {
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM ADMIN_PRIMKOKAS.MIS_BARANG WHERE KODE_BARANG = '".$arr_rule['kode_barang']."'"))<1)
			{
				return $this->error_delete.' [id: '.$arr_rule['kode_barang']."]<br /> SELECT COUNT(1) FROM ADMIN_PRIMKOKAS.MIS_BARANG WHERE KODE_BARANG = '".$arr_rule['kode_barang']."'";
			}else{
				$this->db->delete('ADMIN_PRIMKOKAS.MIS_BARANG', array('kode_barang' => $arr_rule['kode_barang']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

}
?>